﻿namespace Library.Storage
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Runtime.Serialization.Json;
    using System.IO;
    using System.Collections.Generic;

    public class JsonSerializer : ISerializer
    {
        private List<Type> knownTypes = new List<Type>();

        public List<Type> KnownTypes
        {
            get
            {
                return this.knownTypes;
            }
        }

        public void Serialize<T>(Stream stream, T storedObject)
        {
            var serializer = new DataContractJsonSerializer(typeof(T), this.KnownTypes);
            serializer.WriteObject(stream, storedObject);
        }

        public T Deserialize<T>(Stream stream)
        {
            var serializer = new DataContractJsonSerializer(typeof(T), this.KnownTypes);
            return (T)serializer.ReadObject(stream);
        }
    }
}
